package com.soft.service;

import com.soft.dao.DeptDaoImpl;
import com.soft.pojo.Dept;
import com.soft.utils.Result;

import java.util.ArrayList;

/**
 * @author ruoxi
 * @create 2021-12-26 17:22
 */
public class DeptService {
    private DeptDaoImpl deptDao = new DeptDaoImpl();

    public int findDeptCount() {
        return deptDao.selectByAll().size();
    }

    public Dept findDeptByDno(int dno){
        return deptDao.selectDeptByDno(dno);
    }

    public ArrayList<Dept> findDeptByPage(int currentPage, int currentCount) {
        return (ArrayList<Dept>) deptDao.selectDeptByPage(currentPage, currentCount);
    }

    public Result addDept(Dept dept){
        int line = deptDao.add(dept);
        if (line>0){
            return Result.me().setMsg("添加成功");
        }
        return Result.me(false).setMsg("添加失败");
    }

    public Result deleteDept(int dno){
        int line = deptDao.del(dno);
        if (line>0){
            return Result.me().setMsg("删除成功");
        }
        return Result.me(false).setMsg("删除失败");
    }

    public Result editDeptByDno(Dept dept) {
        int line = deptDao.update(dept);
        if (line>0){
            return Result.me().setMsg("修改成功");
        }
        return Result.me(false).setMsg("修改失败");
    }
}
